/*
 * @title: 自定义 v-permission验证权限指令（为验证单个页上按钮权限）
 * @author: andy.ten@tom.com & xukaixing@hotmail.com
 * @Date: 2022-03-25 21:10:15
 * @LastEditors: andy.ten@tom.com
 * @LastEditTime: 2022-03-31 10:47:22
 * @version: 1.0.1
 * @copyright: copyright (c) 2022 andyten
 *  node: you can not copy and/or use and/or modify this program free,
 *  please reserve the segment above.Please mail me if you have any question.
 */
import store from '@/store';

export default {
  inserted(el, binding) {
    const { value } = binding;
    const roles = store.getters && store.getters.roles;
    if (value && value instanceof Array) {
      if (value.length > 0) {
        const permissionRoles = value;
        const hasPermission = roles.some((role) => {
          return permissionRoles.includes(role);
        });
        if (!hasPermission)
          // el.parentNode && el.parentNode.removeChild(el); // 设置 删除
          el.style.disabled = true; // 设置disabled
      }
    } else
      throw new Error(`使用方式： v-permission="['admin','editor']"`);
  }
};
